﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cmsservice.Entity;
using System.Data;

namespace cmsservice.DAL
{
    /// <summary>
    /// 小额产品用户信息数据处理类
    /// </summary>
    public class SmallProductUserInfoDAL
    {
        /// <summary>
        /// 根据手机号二进制信息获取用户唯一标识符
        /// </summary>
        /// <param name="mobileCodeBinary"></param>
        /// <returns></returns>
        public SmallProductUserInfo GetSmallProductUserInfo(Byte[] mobileCodeBinary)
        {
            Tools paramTools = new Tools();

            paramTools.AddSqlParameter("MobileCodeBinary", SqlDbType.VarBinary, mobileCodeBinary);

            return SqlHelper.GetDataByColumns<SmallProductUserInfo>(DBConn.TemporaryDB, "SELECT UserID FROM SmallProductUserInfo WHERE MobileCodeBinary=@MobileCodeBinary", paramTools.GetSqlParameters());
        }

        /// <summary>
        /// 新增小额产品用户信息
        /// </summary>
        /// <param name="smallProductUserInfo"></param>
        /// <returns></returns>
        public int AddSmallProductUserInfo(SmallProductUserInfo smallProductUserInfo)
        { 
            Tools paramTools = new Tools();

            paramTools.AddSqlParameter("UserID", SqlDbType.UniqueIdentifier, smallProductUserInfo.UserID);
            paramTools.AddSqlParameter("MobileCodeBinary", SqlDbType.VarBinary, smallProductUserInfo.MobileCodeBinary);
            paramTools.AddSqlParameter("MobileCodeShow", SqlDbType.VarChar, smallProductUserInfo.MobileCodeShow);

            return SqlHelper.ExecuteNonQuery(DBConn.TemporaryDB, CommandType.Text, "INSERT INTO SmallProductUserInfo(UserID,MobileCodeBinary,MobileCodeShow) VALUES(@UserID,@MobileCodeBinary,@MobileCodeShow)", paramTools.GetSqlParameters());
        }
    }
}
